This document may not be easily readable in this form, try pdf or HTML as alternatives. These have been generated from this file and the software provided by this distribution.
This is a perl module and a script that makes use of App::Basis::ConvertText2
This is a wrapper for pandoc implementing extra fenced code-blocks to allow the creation of charts and graphs etc. Documents may be created a variety of formats. If you want to create nice PDFs then it can use PrinceXML to generate great looking PDFs or you can use wkhtmltopdf to create PDFs that are almost as good, the default is to use pandoc which, for me, does not work as well.
HTML templates can also be used to control the layout of your documents.
The fenced code block handlers are implemented as plugins and it is a simple process to add new ones.
There are plugins to handle
- ditaa
- mscgen
- graphviz
- uml
- gnuplot
- gle
- sparklines
- charts
- barcodes and qrcodes
- and many others
As a perl module you can obtain it from https://metacpan.org/pod/App::Basis::ConvertText2 or install
cpanm App::Basis::ConvertText2
Alternatively it is available from https://github.com/27escape/App-Basis-ConvertText2
You will then be able to use the ct2 script to process files
If you are reading this document in PDF form, then note that all the images are created by the various plugins and included in the output, there is no store of pre-built images. That you can read this proves the plugins all work!
1 Document header and variables
If you are just creating simple things, then you do not need a document header, but to make full use of the templating system, having header information is vital.
Example
title: App::Basis::ConvertText2
format: pdf
date: 2014-05-12
author: Kevin Mulholland
keywords: perl, readme
template: coverpage
version: 5
As you can see, we use a series of key value pairs separated with a colon. The keys may be anything you like, except for the following which have special significance.
- format shows what output format we should default to.
- template shows which template we should use
The keys may be used as variables in your document or in the template, by upper-casing and prefixing and postfixing percent symbols ‘%’
Example
version as a variable %VERSION%
If you want to display the name of a variable without it being interpreted, prefix it with an underscore ’_’, this underscore will be removed in the final document.
Example
%TITLE%
Output
App::Basis::ConvertText2
2 Table of contents
As documents are processed, the HTML headers (H2..H3) are collected together to make a table of contents. This can be used either in your template or document using the TOC variable.
Example
%TOC% will show
Contents
- 19 Start a new page - page
- 20 Columns
- 21 Tree
- 22 Gle / glx
- 23 Gnuplot
- 24 Ploticus
- 25 Badges
- 26 Polaroid
- 27 Box
- 28 Smilies
- 29 Gotchas about variables
- 30 Using ct2 script to process files
Note that if using a TOC, then the HTML headers are changed to have a number prefixed to them, this helps ensure that all the TOC references are unique.
2.1 Skipping header
If you do not want an item added to the toc add the class ‘toc_skip’ to the header
Example
### Skipping header {.toc_skip}
Hopefully you can see that the header for this section is not in the TOC
3 Fenced code-blocks
A fenced code-block is a way of showing that some text needs to be handled differently. Often this is used to allow markdown systems (and pandoc is no exception) to highlight program code.
code-blocks take the form
Example
~~~~{.tag argument1='fred' arg2=3}
contents ...
~~~~
code-blocks ALWAYS start at the start of a line without any preceding whitespace. The ‘top’ line of the code-block can wrap onto subsequent lines, this line is considered complete when the final ‘}’ is seen. There should be only whitespace after the closing ‘}’ symbol before the next line.
We use this construct to create our own handlers to generate HTML or markdown.
Note that only code-blocks described in this documentation have special handlers and can make use of extra features such as buffering.
3.1 Code-block short cuts
Sometimes using a fenced code-block is overkill, especially if the command to be executed does not have any content. So there is a shortcut to this. Additionally this will allow you to use multiple commands on a single line, this may be important in some instances.
Finally note that the shortcut must completely reside on a single line, it cannot span onto a separate next line, the parser will ignore it!
We wrap the command and its arguments with double braces.
Example
{ {.tag argument1='fred' arg2=3}}
To stop the parser from parsing the above example, there is a space character between the opening braces. Do not include this space when creating your markup or things will not work!
4 Buffering data for later use
Sometimes you may either want to repeatedly use the same information or may want to use the output from one of the fenced code-blocks .
To store data we use the to_buffer argument to any code-block.
Example
~~~~{.buffer to_buffer='spark_data'}
1,4,5,20,4,5,3,1
~~~~
If the code-block would normally produce some output that we do not want displayed at the current location then we would need to use the no_output argument.
Example
~~~~{.sparkline title='green sparkline' scheme='green'
from_buffer='spark_data' to_buffer='greenspark' no_output=1}
~~~~
We can also have the content of a code-block replaced with content from a buffer by using the from_buffer argument. This is also displayed in the example above.
To use the contents (or output of a buffered code-block) we wrap the name of the buffer once again with percent ‘%’ symbols, once again we force upper case.
Example
%SPARK_DATA% has content 1,4,5,20,4,5,3,1
%GREENSPARK% has a generated image 
Buffering also allows us to add content into markdown constructs like bullets.
Example
* %SPARK_DATA%
* %GREENSPARK%
Output
- 1,4,5,20,4,5,3,1
5 Sparklines
Sparklines are simple horizontal charts to give an indication of things, sometimes they are barcharts but we have nice smooth lines.
The only valid contents of the code-block is a single line of comma separated numbers.
The full set of optional arguments is
- title
- used as the generated images ‘alt’ argument
- bgcolor
- background color in hex (123456) or transparent
- line
- color or the line, in hex (abcdef)
- color
- area under the line, in hex (abcdef)
- scheme
- color scheme, only things in red blue green orange mono are valid
- size
- size of image, default 80x20, widthxheight
Example
~~~~{.buffer to_buffer='spark_data'}
1,4,5,20,4,5,3,1
~~~~
here is a standard sparkline
~~~~{.sparkline title='basic sparkline' }
1,4,5,20,4,5,3,1
~~~~
or we can draw the sparkline using buffered data
~~~~{.sparkline title='blue sparkline' scheme='blue' from_buffer='spark_data'}
~~~~
Output
here is a standard sparkline
or we can draw the sparkline using buffered data
6 Charts
Displaying charts is very important when creating reports, so we have a simple chart code-block.
The various arguments to the code-block are shown in the examples below, hopefully they are self explanatory.
We will buffer some data to start
Example
~~~~{.buffer to='chart_data'}
apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
~~~~
The content comprises a number of lines of comma separated data items. The first line of the content is the legends, the subsequent lines are numbers relating to each of these legends.
6.1 Pie chart
Example
~~~~{.chart format='pie' title='chart1' from_buffer='chart_data'
size='400x400' xaxis='things xways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
Output
6.2 Bar chart
Example
~~~~{.chart format='bars' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things ways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
Output
6.3 Mixed chart
Example
~~~~{.chart format='mixed' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things xways' axis='Vertical things'
legends='a,b,c,d,e,f,g,h' types='lines linepoints lines bars' }
~~~~
Output
7 Message Sequence Charts - mscgen
Software (or process) engineers often want to be able to show the sequence in which a number of events take place. We use the msc program for this. This program needs to be installed onto your system to allow this to work
The content for this code-block is EXACTLY the same that you would use as input to msc
There are only optional 2 arguments
- title
- used as the generated images ‘alt’ argument
- size
- size of image, widthxheight
Example
~~~~{.mscgen title="mscgen1" size="600x400}
# MSC for some fictional process
msc {
a,b,c;
a->b [ label = "ab()" ] ;
b->c [ label = "bc(TRUE)"];
c=>c [ label = "process(1)" ];
c=>c [ label = "process(2)" ];
...;
c=>c [ label = "process(n)" ];
c=>c [ label = "process(END)" ];
a<<=c [ label = "callback()"];
--- [ label = "If more to run", ID="*" ];
a->a [ label = "next()"];
a->c [ label = "ac1()\nac2()"];
b<-c [ label = "cb(TRUE)"];
b->b [ label = "stalled(...)"];
a<-b [ label = "ab() = FALSE"];
}
~~~~
Output
8 Diagrams Through Ascii Art - ditaa
This is a special system to turn ASCII art into pretty pictures, nice to render diagrams. You do need to make sure that you are using a proper monospaced font with your editor otherwise things will go awry with spaces. See ditaa for reference.
The content for this code-block must be the same that you would use to with the ditaa software
- title
- used as the generated images ‘alt’ argument
- size
- size of image, default 80x20, widthxheight
Example
~~~~{.ditaa }
Full example
+--------+ +-------+ +-------+
| | --+ ditaa +--> | |
| Text | +-------+ |diagram|
|Document| |!magic!| | |
| {d}| | | | |
+---+----+ +-------+ +-------+
: ^
| Lots of work |
\-------------------------+
~~~~
Output
9 UML Diagrams
Software engineers love to draw diagrams, PlantUML is a java component to make this simple.
You will need to have a script on your system called ‘uml’ that calls java with the component.
Here is mine, it is also available in the scripts directory in the
#!/bin/bash
# run plantuml
# moodfarm@cpan.org
# we assume that the plantuml.jar file is in the same directory as this executable
EXEC_DIR=`dirname $0`
PLANTUML="$EXEC_DIR/plantuml.jar"
INPUT=$1
OUPUT=$2
function show_usage {
arg=$1
err=$2
if [ "$err" == "" ] ; then
err=1
fi
"Create a UML diagram from an input text file
(see http://plantuml.sourceforge.net/ for reference)
usage: $0 inputfile outputfile.png
"
if [ "$arg" != "" ] ; then
echo "$arg
"
fi
exit $err
}
if [ "$INPUT" == "-help" ] ; then
show_usage "" 0
fi
if [ ! -f "$INPUT" ] ; then
show_usage "ERROR: Could not find input file $1"
fi
if [ "$OUPUT" == "" ] ; then
show_usage "ERROR: No output file specified"
fi
# we use the pipe option to control output into the file we want
cat "$INPUT" | java -jar $PLANTUML -nbthread auto -pipe >$OUPUT
# exit 0
The content for this code-block must be the same that you would use to with the PlantUML software
The arguments allowed are
- title
- used as the generated images ‘alt’ argument
- size
- size of image, default 80x20, widthxheight
Example
~~~~{.uml }
' this is a comment on one line
/' this is a
multi-line
comment'/
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
~~~~
Output
PlantUML can also create simple application interfaces See Salt
Example
~~~~{.uml }
@startuml
salt
{
Just plain text
[This is my button]
() Unchecked radio
(X) Checked radio
[] Unchecked box
[X] Checked box
"Enter text here "
^This is a droplist^
{T
+ World
++ America
+++ Canada
+++ **USA**
++++ __New York__
++++ Boston
+++ Mexico
++ Europe
+++ Italy
+++ Germany
++++ Berlin
++ Africa
}
}
@enduml
~~~~
Output
10 Umltree
Draw a bulleted list as a tree using the plantuml salt GUI layout tool. Bullets are expected to be indented by 4 spaces, we will only process bullets that are * + or -.
Example
~~~~{.umltree}
* one
* 1.1
* two
* two point 1
* 2.2
* three
* 3.1
* 3.2
* three point 3
* four
* five
* six
* 3 . seven
~~~~
Output
11 Graphviz
graphviz allows you to draw connected graphs using text descriptions.
The content for this code-block must be the same that you would use to with the graphviz software
The arguments allowed are
- title
- used as the generated images ‘alt’ argument
- size
- size of image, default 80x20, widthxheight
Example
~~~~{.graphviz title="graphviz1" size='600x600'}
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
subgraph cluster_1 {
node [style=filled];
b0 -> b1 -> b2 -> b3;
label = "process #2";
color=blue
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
~~~~
Output
12 Venn diagram
Creating venn diagrams may sometimes be useful, though to be honest this implementation is not great, if I could find a better way to do this then I would!
Example
~~~~{.venn title="sample venn diagram"
legends="team1 team2 team3" scheme="rgb" explain='1'}
abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward
~~~~
Output
- only in team1 : momo chris julien jack abel
- only in team2 : antonio isabel delta
- team1 and team2 share : albert
- only in team3 : gerald lucia john
- team1 and team3 share :
- team2 and team3 share : jake kevin
- team1, team2 and team3 share : edward
13 Barcodes
Sometimes having barcodes in your document may be useful, certainly qrcodes are popular.
The code-block only allows a single line of content. Some of the barcode types need content of a specific length, warnings will be generated if the length is incorrect.
The arguments allowed are
- title
- used as the generated images ‘alt’ argument
- height
- height of image
- notext
- flag to show we do not want the content text printed underneath the barcode.
- version
- version of qrcode, defaults to ‘2’
- pixels
- number of pixels that is a ‘bit’ in a qrcode, defaults to ‘2’
13.1 Code39
Example
~~~~{.barcode type='code39'}
123456789
~~~~
Output
13.2 EAN8
Only allows 8 characters
Example
~~~~{.barcode type='ean8'}
12345678
~~~~
Output
13.3 EAN13
Only allows 13 characters
Example
~~~~{.barcode type='EAN13'}
1234567890123
~~~~
Output
13.4 COOP2of5
Example
~~~~{.barcode type='COOP2of5'}
12345678
~~~~
Output
13.5 IATA2of5
Example
~~~~{.barcode type='IATA2of5'}
12345678
~~~~
Output
13.6 Industrial2of5
Example
~~~~{.barcode type='Industrial2of5'}
12345678
~~~~
Output
13.7 ITF
Example
~~~~{.barcode type='ITF'}
12345678
~~~~
Output
13.8 Matrix2of5
Example
~~~~{.barcode type='Matrix2of5'}
12345678
~~~~
Output
13.9 NW7
Example
~~~~{.barcode type='NW7'}
12345678
~~~~
Output
13.10 QR code
As qrcodes are now quite so prevalent, they have their own code-block type.
We can do qr codes, just put in anything you like, this is a URL for bbc news
Example
~~~~{.qrcode }
http://news.bbc.co.uk
~~~~
To change the size of the barcode
~~~~{.qrcode height='80'}
http://news.bbc.co.uk
~~~~
To use version 1
Version 1 only allows 15 characters
~~~~{.qrcode height=60 version=1}
smaller text..
~~~~
To change pixel size
~~~~{.qrcode pixels=5}
smaller text..
~~~~
Output
To change the size of the barcode
To use version 1
Version 1 only allows 15 characters
To change pixel size
14 YAML convert to JSON
Software engineers often use JSON to transfer data between systems, this often is not nice to create for documentation. YAML which is a superset of JSON is much cleaner so we have a
Example
~~~~{.yamlasjson }
list:
- array: [1,2,3,7]
channel: BBC3
date: 2013-10-20
time: 20:30
- array: [1,2,3,9]
channel: BBC4
date: 2013-11-20
time: 21:00
~~~~
Output
{
"list" : [
{
"array" : [
1,
2,
3,
7
],
"time" : "20:30",
"date" : "2013-10-20",
"channel" : "BBC3"
},
{
"array" : [
1,
2,
3,
9
],
"channel" : "BBC4",
"time" : "21:00",
"date" : "2013-11-20"
}
]
}